<?php

namespace app\behaviors;

use app\components\LogComponent;

class LogBehavior extends BaseBehavior
{

    /**
     * 日志编码方式
     * @var string
     */
    public $encoding = 'json';
    /**
     * Getter for $encoding
     * @return
     */
    public function getEncoding()
    {
        return $this->encoding;
    }

    /**
     * Setter for $encoding
     * @param string 设置 $encoding 的值
     * @return self
     */
    public function setEncoding($encoding)
    {
        $this->encoding = $encoding;
        return $this;
    }

    public function events()
    {
        return [
            LogComponent::EVENT_BEFORE_LOG => 'beforeLog',
            LogComponent::EVENT_AFTER_LOG => 'afterLog',
        ];
    }

    public function beforeLog($event)
    {
        $event->log .= ':success';
        echo 'behavior:', $this->encoding, PHP_EOL;
    }

    public function afterLog($event)
    {
        // echo uniqid(), PHP_EOL;
    }
}
